package cn.enilu.flash.code;

import java.util.Map;

/**
 * @author: tonglele
 * @date: created in 2019-11-12
 * @description: MapEntry
 * @modified by:tonglele
 */
public class MapEntry<K,V> implements Map.Entry<K,V> {

    private K key;
    private V value;

    public MapEntry(K key,V value){
        this.key = key;
        this.value = value;
    }

    @Override
    public K getKey() {
        return key;
    }

    @Override
    public V getValue() {
        return value;
    }

    @Override
    public V setValue(V v) {
        V result = v;
        value = v;
        return result;
    }

    public int hashCode() {
        return (key==null ? 0 : key.hashCode()) ^ (value == null ? 0:value.hashCode());
    }

    public boolean equals(Object obj) {
        if(!(obj instanceof MapEntry)) return false;
        MapEntry me = (MapEntry) obj;

        return (key == null ? me.getKey() == null : key.equals(me.getKey())) &&
                (value==null ? me.getValue() == null: value.equals(me.getValue()));

    }

    public String toString(){
        return key + "=" + value;
    }
}



